import 'package:efood_multivendor/controller/localization_controller.dart';
import 'package:efood_multivendor/data/model/response/language_model.dart';
import 'package:efood_multivendor/helper/size_config.dart';
import 'package:efood_multivendor/util/app_constants.dart';
import 'package:efood_multivendor/util/dimensions.dart';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:efood_multivendor/helper/size_config.dart' as Size;

enum LanguageSelected {
  english,
  amharic,
}

class LanguageWidget extends StatelessWidget {
  final LanguageModel languageModel;
  final LocalizationController localizationController;
  final int index;
  LanguageWidget(
      {required this.languageModel,
      required this.localizationController,
      required this.index});

  @override
  Widget build(BuildContext context) {
    Size.init(context);

    return InkWell(
      onTap: () {
        localizationController.setSelectIndex(index);
      },
      child: Padding(
        padding: const EdgeInsets.all(Dimensions.PADDING_SIZE_SMALL),
        child: Container(
            width: 90.w,
            decoration: BoxDecoration(
              color: Theme.of(context).cardColor,
              borderRadius: BorderRadius.only(
                  topRight: Radius.circular(Dimensions.RADIUS_SMALL * 2.8),
                  topLeft: Radius.circular(Dimensions.RADIUS_SMALL * 2.4),
                  bottomLeft: Radius.circular(Dimensions.RADIUS_SMALL * 2.4),
                  bottomRight: Radius.circular(Dimensions.RADIUS_SMALL * 2.8)),
              boxShadow: [
                BoxShadow(
                    color: Colors.grey[Get.isDarkMode ? 800 : 200]!,
                    blurRadius: 5,
                    spreadRadius: 1)
              ],
            ),
            child: Row(
              mainAxisSize: MainAxisSize.max,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Radio<LanguageModel>(
                        fillColor: MaterialStateProperty.all(
                            Theme.of(context).colorScheme.secondary),
                        value: localizationController.languages[index],
                        groupValue: AppConstants
                            .languages[localizationController.selectedIndex],
                        onChanged: (p) {
                          if (p != null) {
                            onChanged(p);
                          }
                        }),
                    SizedBox(
                      width: 1.w,
                    ),
                    Text(
                      languageModel.languageName ?? '',
                      style: TextStyle(color: Colors.black),
                    ),
                  ],
                ),
                Spacer(),
                Image.asset(
                  languageModel.imageUrl!,
                ),
              ],
            )),
      ),
    );
  }

  void onChanged(LanguageModel value) {
    localizationController.setSelectIndex(index);
  }
}
